﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaygunDiplomacy.Events;

namespace RaygunDiplomacy.Activities
{
   public abstract class Activity
   {
      FastSubject<CancelableEventArgs> interupting = new FastSubject<CancelableEventArgs>();

      public IObservable<CancelableEventArgs> Interupting
      {
         get { return interupting; }
      }

      protected virtual void OnInterupting(CancelableEventArgs args)
      {
         interupting.OnNext(args);
      }

      FastSubject<EventArgs> interupted = new FastSubject<EventArgs>();

      protected virtual void OnInterupted()
      {
         interupted.OnNext(EventArgs.Empty);
      }

      public IObservable<EventArgs> Interupted
      {
         get { return interupted; }
      }

      public void Interrupt()
      {
         CancelableEventArgs cancelEventArgs = new CancelableEventArgs();

         OnInterupting(cancelEventArgs);

         if (cancelEventArgs.Canceled == false)
         {
            OnInterupted();
         }
      }
   }
}
